package com.edu.lighthouse.web;

import com.edu.lighthouse.conf.Result;
import com.edu.lighthouse.pojo.CardInfo;
import com.edu.lighthouse.pojo.User;
import com.edu.lighthouse.pojo.vo.CardBaseVo;
import com.edu.lighthouse.pojo.vo.UserBaseVo;
import com.edu.lighthouse.pojo.vo.UserRegVo;
import com.edu.lighthouse.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/api/v1/user")
public class UserController {

    @Autowired
    UserService userService;

    private Logger log = LoggerFactory.getLogger(UserController.class);

    @PostMapping("/list")
    public Result listLarge(@RequestBody UserBaseVo UserBaseVo) {
        log.info("用户列表, UserBaseVo={}", UserBaseVo);
        List<UserRegVo> list = userService.list(UserBaseVo);
        return Result.success(list);
    }
    @GetMapping("/resetPass")
    public Result restPass(Integer userId){
        log.info("重置用户列表，userId={}",userId);
        if(userService.resetPass(userId) > 0){
            return Result.success("密码重置成功，初始密码为：123456");
        }
        return Result.error("密码重置失败，请重试！");
    }
    @GetMapping("/delUser")
    public Result delUser(Integer userId){
        log.info("删除用户，userId={}",userId);
        if(userService.updateUserState(userId,1) > 0){
            return Result.success("用户删除成功！");
        }
        return Result.error("用户删除失败，请重试！");

    }
}
